package dispatcher.group.gui.network;

import dispatcher.gui.GroupDispatcherView;
import dispatcher.gui.event.StatusUpdateThreadPool;
import messages.BaseMessage;
import messages.MessageType;
import messages.observer.EventCollectionMessage;
import observer.ObserverListener;
import state.Globals;

/**
 * This class will wait for a ElevatorEventMessage message to be send back from the GroupDispatcher
 * and will update the GroupDispatcherStateHandler with the message informations
 * @author Caleb
 *
 */
public class GroupDispatcherGUIObserverListener implements ObserverListener {

	@Override
	public void handleMessage(BaseMessage message) {
		Globals.getLogger().log("Message is : " + message.getMessageType(), this.getClass().getName(), "handleMessage");
		
		// Checks if the message type is ElevatorEventMessage
		if (message.getMessageType() == MessageType.EventCollectionMessage){
			
			EventCollectionMessage mess = (EventCollectionMessage)message;
			// Creates a new request thread for updating the GroupDispatcherStateHandler
			StatusUpdateThreadPool.getInstance().updateStatus(mess.getEvents());
		}else if (message.getMessageType() == MessageType.DeregistrationMessage){
			GroupDispatcherView.getInstance().shutdownNetwork();
		}
	}

}
